<?php
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include 'includes/header.php';
my_header('Казина :: Jwakk');
?>
			
			<div class="line"></div>
			<div class="mainConteiner">
			
			<?php include 'includes'.DIRECTORY_SEPARATOR.'top.php'; ?>
			<div class="topDelimiter"></div>
			
			<div class="content">
			
			<table cellspacing="0" cellpadding="0" width="100%"><tr>
			
			<td class="Mainmenu" valign="top">
                            <a href="index.php"><div class="manuB">Казина</div></a>
                            <a href="buyCasino.php"><div class="manuB">Купи казино</div></a>
                            <a href="yoursC.php"><div class="manuB">Твои казина</div></a>
                            <a href="fight.php"><div class="manuB">Сбий се</div></a>
                            <a href="work.php"><div class="manuB">Работа</div></a>
                            <a href="zalozi.php"><div class="manuOnB">Залози</div></a>
                            <a href="coffee.php"><div class="manuB">Градът</div></a>
                            <a href="profile.php?user=<?php echo $_SESSION['user_info']['user']; ?>"><div class="manuB">Профил</div></a>
                            <?php
								$mes_q = mysql_query('SELECT id FROM message WHERE `do`="'.$_SESSION['user_info']['user'].'" AND `read`="0"');
								$mes_n = mysql_num_rows($mes_q);
								echo '<a href="mail.php"><div class="manuB">Съобщения ['.$mes_n.']</div></a>';
							?>
                            <a href="index.php?logout"><div class="manuBLogOut">Изход</div></a>

                            <br/>
                            <a href="#"><img alt="Последвайте Jwakk в Facebook" src="img/facebook.png" /></a>
                            <a href="#"><img alt="Последвайте Jwakk в Twitter" src="img/twitter.png" /></a>
                            <a href="#"><img alt="Абонирайте се за RSS емисии" src="img/rss.png" /></a>
                        </td>
				
				<td valign="top">
					<div class="gameBorder">
					<div class="TheGame">
					<div class="gameTitle">Залози :: Футбол</div>	
					<br />
					
					<?php
					if(isset($_GET['id']) AND isset($_GET['for'])){
						$id = $_GET['id'];
						$for = $_GET['for'];
						$otb = $_GET['otb'];
								if($money>100){
										$user_check = mysql_query('SELECT otbor FROM user_zalog WHERE id="'.$id.'" AND user="'.$_SESSION['user_info']['user'].'"');
										if(mysql_num_rows($user_check)==1){
											echo 'Вие вече сте заложели.';
										}
										else{
												if($otb==1 OR $otb==2){
												if($otb==1){
													$id_q = mysql_query('SELECT otbor1 FROM zalog WHERE id="'.$id.'"');
													$id_f = mysql_fetch_assoc($id_q);
														if($id_f['otbor1']==$for){
															mysql_query('INSERT INTO user_zalog(id,otbor,user,data,left_right)
															VALUES("'.$id.'","'.$for.'","'.$_SESSION['user_info']['user'].'",'.time().',"'.$otb.'")');
															
															mysql_query('UPDATE users SET money=money-100 WHERE
															user="'.$_SESSION['user_info']['user'].'"');
															
														}
														else{
															echo '<meta http-equiv="refresh" content="0;url=zalozi.php">';
														}	
												}
												elseif($otb==2){
														$id_q = mysql_query('SELECT otbor2 FROM zalog WHERE id="'.$id.'"');
														$id_f = mysql_fetch_assoc($id_q);
															if($id_f['otbor2']==$for){
																mysql_query('INSERT INTO user_zalog(id,otbor,user,data,left_right)
																VALUES("'.$id.'","'.$for.'","'.$_SESSION['user_info']['user'].'",'.time().',"'.$otb.'")');
																
																mysql_query('UPDATE users SET money=money-100 WHERE
																user="'.$_SESSION['user_info']['user'].'"');
															}
															else{
																echo '<meta http-equiv="refresh" content="0;url=zalozi.php">';
															}	
												}
											}
											else{
												echo '<meta http-equiv="refresh" content="0;url=zalozi.php">';
											}
										}
								}
								elseif($money<100){
									echo 'Нямате достатъчно пари.';
								}
							
					}
						$mach_q = mysql_query('SELECT id,otbor1,otbor2 FROM zalog ORDER BY data DESC LIMIT 3');
						while($mach_f = mysql_fetch_assoc($mach_q)){
							$dali_q = mysql_query('SELECT otbor,left_right FROM user_zalog WHERE id="'.$mach_f['id'].'" AND user="'.$_SESSION['user_info']['user'].'"');
							if(mysql_num_rows($dali_q)==0){
								echo '<div class="casinostat"> <a href="zalozi.php?id='.$mach_f['id'].'&for='.$mach_f['otbor1'].'&otb=1" class="zalog">'.$mach_f['otbor1'].'</a> &nbsp;vs&nbsp; <a href="zalozi.php?id='.$mach_f['id'].'&for='.$mach_f['otbor2'].'&otb=2" class="zalog">'.$mach_f['otbor2'].'</a></div>';
							}
							elseif(mysql_num_rows($dali_q)==1){
								$dali_f = mysql_fetch_assoc($dali_q);
									if($dali_f['left_right']==1){
										echo '<div class="casinostat"> <span href="#" class="zalojil">'.$dali_f['otbor'].'</span> &nbsp;vs&nbsp; <span href="#"  class="zalog"> &nbsp;'.$mach_f['otbor2'].'</span></div>';
									}
									elseif($dali_f['left_right']==2){
										echo '<div class="casinostat"> <span href="#" class="zalog">'.$mach_f['otbor1'].'</span> &nbsp;vs&nbsp; <span href="#" class="zalojil"> &nbsp;'.$dali_f['otbor'].'</span></div>';
									}
							}
							
						}
					?>
					
					
					<!--<div class="casinostat"> <a href="#" class="zalog">Локо Мездра </a> &nbsp;vs&nbsp; <a href="#" class="zalog">Локо Пловдив </a></div>
					<div class="casinostat"> <span href="#" class="zalog">Барселона</span> &nbsp;vs&nbsp; <span href="#" class="zalojil"> &nbsp;Милан</span></div>-->
					
					<div class="access">Печалбите от мачовете ще бъдат изчислени на 15.11.2011 (утре).</div>
					
					</div>
					</div>
					<div class="help"> <a href="#">Помощ</a> | <a href="#">FAQ</a> | <a href="#">Условия</a> | <a href="#">Facebook</a></div>
				</td>
			
			</tr></table>
			
			
			<div class="footer">
				© JwakK.com · Всички права запазени · <a href="#">Условия за ползване</a>
			</div>
			</div>
			</div>
			
			<div class="bottom"></div>
			
			

			
			
			
			
			
			</body>
			</html>